package ui;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import data.BankDatabase;

/**
 * @author Matthias
 * @author Niels Christian Mouritsen
 */
public class UserMenuDelete extends JPanel {

	private final JLabel lbl_Header;
	private final JComboBox<String> comboBox_Delete;
	private final JButton btn_Submit;
	private final JButton btn_Back;
	private final JLabel lbl_Intro;
	private final JLabel logo_ATM;
	
	/** Declaring the BankDatabase object by the type bdb **/
	private final BankDatabase bdb;
	
	/** Declaring the Screen object by the type screen **/
	private final Screen screen;

	/** Constructor of UserMenuDelete
	 * @param screen referring to the Screen object
	 */
	public UserMenuDelete(final Screen screen) {

		this.screen = screen;
		this.bdb = screen.getClassATM().getClassBankDatabase();
		
		setPreferredSize(new Dimension(600, 480));
		setLayout(null);
		
		lbl_Header = new JLabel("Delete Account");
		lbl_Header.setFont(new Font("SansSerif", Font.BOLD, 26));
		lbl_Header.setBounds(190, 25, 189, 34);
		add(lbl_Header);

		comboBox_Delete = new JComboBox<String>();
		comboBox_Delete.setFont(new Font("SansSerif", Font.PLAIN, 16));
		comboBox_Delete.setBounds(138, 186, 291, 53);
		addAllAcc();
		add(comboBox_Delete);
		
		btn_Submit = new JButton("Submit");
		btn_Submit.setFont(new Font("SansSerif", Font.PLAIN, 16));
		btn_Submit.setBounds(400, 340, 130, 50);
		add(btn_Submit);
		
		btn_Back = new JButton("Back");
		btn_Back.setFont(new Font("SansSerif", Font.PLAIN, 16));
		btn_Back.setBounds(70, 340, 130, 50);
		add(btn_Back);
		
		lbl_Intro = new JLabel("Which account do you want to delete?");
		lbl_Intro.setFont(new Font("SansSerif", Font.BOLD, 16));
		lbl_Intro.setBounds(138, 141, 291, 34);
		add(lbl_Intro);
		
		logo_ATM = new JLabel("");
		logo_ATM.setIcon(new ImageIcon(UserMenuDelete.class.getResource("/pic/LOGO Mini.png")));
		logo_ATM.setBounds(15, 15, 50, 50);
		add(logo_ATM);
	}
	
	/** Adds action listeners, in order to define an action 
	 * when a component is called
	 * @param e
	 */
	public final void addActionListener(final ActionListener e) {
		btn_Back.addActionListener(e);
		btn_Submit.addActionListener(e);
		comboBox_Delete.addActionListener(e);
	}

	/**
	 * @return back button
	 */
	public final JButton getBtnBack() {
		return btn_Back;
	}
	
	/**
	 * @return submit button
	 */
	public final JButton getBtnSubmit(){
		return btn_Submit;
	}
	
	/**
	 * @return combo box
	 */
	public final JComboBox<String> getComboBox() {
		return comboBox_Delete;
	}
	
	/**
	 * adding all existing accounts of the current user
	 * to the combobox, in order to select one and
	 * delete the select item by pressing the submit button
	 */
	public final void addAllAcc() {
		comboBox_Delete.removeAllItems();	
		String[] account = bdb.getClassUser().getAccountChanger();
		for (int i = 0; i < account.length; i++) {
			comboBox_Delete.addItem(account[i]);		
		}
		screen.pack();
	}
	
	/**
	 * @return the selected user's accountnumber from the combobox 
	 * in order to delete the selected one
	 */
	public final int getSpecificAccNr() {
		int[] info = new int[bdb.getClassUser().getAccountList().size()];
	    for (int i = 0; i < bdb.getClassUser().getAccountList().size(); i++) {
			info[i] = bdb.getClassUser().
					getAccountList().get(i).getAccountNumber();
		}
	    return info[comboBox_Delete.getSelectedIndex()];
	}

} // end UserMenuDelete class